home *** CD-ROM | disk | FTP | other *** search
- /**
- * Scout - The Amiga System Monitor
- *
- *------------------------------------------------------------------
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * You must not use this source code to gain profit of any kind!
- *
- *------------------------------------------------------------------
- *
- * @author Andreas Gelhausen
- * @author Richard Körber <rkoerber@gmx.de>
- */
-
-
-
- #include "scout_commands.h"
-
- extern struct ExecBase *SysBase;
-
- int comcnt;
-
- struct Remember *ComRememberKey;
-
- char * GetUCType (LONG uc) {
- char *UCTypeText[] = {
- "SYSTEM","INTERNAL","DISABLED"
- };
-
- LONG UCType[] = {
- CMD_SYSTEM,CMD_INTERNAL,CMD_DISABLED,NULL
- };
-
- int i = 0;
-
- while (UCType[i]) {
- if (uc == UCType[i]) {
- return (UCTypeText[i]);
- }
- i++;
- }
- return (NULL);
- }
-
- __asm LONG comlist_dspfunc(register __a2 char **array, register __a1 struct CommandEntry *comentry, register __a0 struct Hook *hook) {
- if (comentry) {
- *array++ = comentry->cm_address;
- *array++ = comentry->cm_name;
- *array++ = comentry->cm_uc;
- *array++ = comentry->cm_lower;
- *array++ = comentry->cm_upper;
- *array++ = comentry->cm_size;
- *array = NULL;
- } else {
- *array++ = ESC "bAddress";
- *array++ = ESC "bName";
- *array++ = ESC "bUseCount";
- *array++ = ESC "b" ESC "cLower";
- *array++ = ESC "b" ESC "cUpper";
- *array++ = ESC "bSize";
- *array++ = NULL;
- }
- return(0);
- }
-
- struct Hook comlist_dsphook = {
- {NULL, NULL},
- (ULONG (* )())comlist_dspfunc,
- NULL, NULL
- };
-
- void FreeCommands (void) {
- MyFreeStructs (&ComRememberKey, NULL, comlist);
- }
-
- int GetCommands (struct CommandEntry **first) {
- struct Segment *segment;
- struct CommandEntry *comentry,*previous = NULL;
- long *seg, size;
- char *tmp;
-
- int comcnt = 0;
- *first = 0;
-
- if (clientstate) {
- if (SendDaemon ("GetComList")) {
- while ((comentry = AllocRemember (&ComRememberKey, sizeof (struct CommandEntry), MEMF_ANY|MEMF_CLEAR)) \
- && (ReceiveDecodedEntry ((UBYTE *) comentry, sizeof (struct CommandEntry)))) {
- IsHex (comentry->cm_address, (long *) &comentry->cm_adr);
-
- if (! *first)
- *first = comentry;
- if (previous)
- previous->cm_next = comentry;
-
- comcnt++;
- previous = comentry;
- }
- }
- } else {
- segment = (struct Segment *) (((long) DEVINFO->di_NetHand)<<2);
- while ((segment) && (comentry = AllocRemember (&ComRememberKey, sizeof (struct CommandEntry), MEMF_ANY|MEMF_CLEAR))) {
- if (! *first)
- *first = comentry;
- if (previous)
- previous->cm_next = comentry;
-
- comentry->cm_adr = (char *) segment;
- sprintf (comentry->cm_address, "$%08x", segment);
- strncpy (comentry->cm_name, (char *) &segment->seg_Name + 1, (UBYTE) segment->seg_Name[0]);
-
- if (tmp = GetUCType (segment->seg_UC)) {
- strcpy (comentry->cm_uc, tmp);
-
- strcpy (comentry->cm_lower, ESC "c---");
- strcpy (comentry->cm_upper, ESC "c---");
- strcpy (comentry->cm_size, ESC "c---");
-
- comcnt++;
- previous = comentry;
- } else {
- sprintf (comentry->cm_uc, "%d", segment->seg_UC - 1);
-
- seg = (long *) (((long) segment->seg_Seg)<<2);
- comcnt++;
- while (seg) {
- sprintf (comentry->cm_lower, "$%x", ((char *) seg) + 4);
- size = *(seg - 1);
- sprintf (comentry->cm_size, "%d", size);
- sprintf (comentry->cm_upper, "$%x", ((char *) seg) - 4 + size);
-
- previous = comentry;
- if (seg = (long *) ((*seg)<<2)) {
- comentry = AllocRemember (&ComRememberKey, sizeof (struct CommandEntry), MEMF_ANY|MEMF_CLEAR);
- if (previous)
- previous->cm_next = comentry;
- comentry->cm_address[0] = ' ';
- }
- }
- }
- segment = (struct Segment *) (segment->seg_Next<<2);
- }
- }
- return (comcnt);
- }
-
- void PrintCommands (char *filename) {
- int i=1;
- BPTR handle;
- struct CommandEntry *entryp;
-
- handle = HandlePrintStart (filename);
- if ((handle) && (PrintOneLine (handle, "\n Address Name UseCount Lower Upper Size\n\n"))) {
- if (! WI_Commands) {
- i = GetCommands (&entryp);
- }
- if (i) {
- for (i=0;;i++) {
- if (WI_Commands)
- DoMethod (comlist,MUIM_List_GetEntry,i,&entryp);
- if (!entryp) break;
-
- sprintf (tmpstr2, " %9ls %-15.15ls %8ls", entryp->cm_address, entryp->cm_name, entryp->cm_uc);
- if ((entryp->cm_uc[0] == 'I') || (entryp->cm_uc[0] == 'S') || (entryp->cm_uc[0] == 'D')) {
- sprintf (tmpstr, " %9ls %9ls %7ls\n", entryp->cm_lower+2, entryp->cm_upper+2, entryp->cm_size+2);
- strcat (tmpstr2, tmpstr);
- } else {
- sprintf (tmpstr, " %9ls %9ls %7ls\n", entryp->cm_lower, entryp->cm_upper, entryp->cm_size);
- strcat (tmpstr2, tmpstr);
- }
- if (! (PrintOneLine (handle, tmpstr2)))
- break;
-
- if (! WI_Commands)
- entryp = entryp->cm_next;
- }
- }
- }
- HandlePrintStop();
- }
-
- void ShowCommands (void) {
- struct CommandEntry *com;
-
- ApplicationSleep();
- set (comlist,MUIA_List_Quiet,TRUE);
- set (comlist,MUIA_List_CompareHook,comlist_cmphook_ptr);
- set (BT_ComRemove, MUIA_Disabled, TRUE);
-
- FreeCommands();
- comcnt = GetCommands (&com);
-
- while (com) {
- InsertSortedEntry (comlist, (APTR *) &com);
- com = com->cm_next;
- }
-
- SetCountText (comcount, comcnt);
- AwakeApplication();
- set (comlist,MUIA_List_Quiet,FALSE);
- }
-
- void SendComList (void) {
- struct CommandEntry *com;
-
- FreeCommands();
- comcnt = GetCommands (&com);
-
- while (com) {
- SendEncodedEntry ((UBYTE *) com, sizeof (struct CommandEntry));
- com = com->cm_next;
- }
- FreeCommands();
- }
-
-